package com.dyw.spzx.manager.service.lmpl;

import com.dyw.spzx.manager.mapper.SysRoleMapper;
import com.dyw.spzx.manager.service.SysRoleService;
import com.dyw.spzx.manager.service.SysUserRoleService;
import com.dyw.spzx.model.dto.system.SysRoleDto;
import com.dyw.spzx.model.entity.system.SysRole;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SysRoleServiceImpl implements SysRoleService {
    @Autowired
    private SysRoleMapper sysRoleMapper;
    @Autowired
    private SysUserRoleService sysUserRoleService;


    // 查询角色列表
    @Override
    public PageInfo<SysRole> findByPage(Integer pageNum, Integer pageSize, SysRoleDto sysRoleDto) {
        PageHelper.startPage(pageNum,pageSize);
        List<SysRole> sysRoleList = sysRoleMapper.findByPage(pageNum, pageSize,sysRoleDto);
        PageInfo<SysRole> sysRolePageInfo = new PageInfo<>(sysRoleList);
        return sysRolePageInfo;
    }


    // 添加角色
    @Override
    public void saveSysRole(SysRole sysRole) {
        sysRoleMapper.saveSysRole(sysRole);

    }

    // 修改角色信息
    @Override
    public void updateSysRole(SysRole sysRole) {
        sysRoleMapper.updateSysRole(sysRole);
    }

    // 删除角色信息
    @Override
    public void deleteRoleById(Integer roleId) {
        sysRoleMapper.deleteRoleById(roleId);
    }

    // 查询所有角色信息
    @Override
    public Map<String, Object> findAllRoles(Long userId) {
        // 查询所有角色数据
        List<SysRole> sysRoleList = sysRoleMapper.findAllRoles();
        // 查询当前用户的角色数据
        List<Long> sysRoleIds = sysUserRoleService.findUserRoleByUserId(userId);
        // 响应数据
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("allRolesList",sysRoleList);
        resultMap.put("sysUserRoles",sysRoleIds);
        return resultMap;
    }
}
